// File name: KnightBoard.java
// This file defines a chess board abstraction
// for knight tour problem.

import java.util.*;
class KnightBoard
{
    private int[][] status;
    // 0: (still available, either never visited or visted but backtracked)
    // > 0: (visited and possiblly leads to a solution)

    int dimension;
    // This board is dimension by dimension board;

    public KnightBoard(int dimension)
    {
	status = new int[dimension][dimension];
	for (int i = 0; i < dimension; i++)
	    for (int j = 0; j < dimension; j++)
		status[i][j] = 0;
	this.dimension = dimension;
    }

    // Check the position 'pos' is valid (indexes are not out of bound and the 
    // position is still available) or not.
    public boolean valid(Position pos)
    {     }

    // Set the status of the position 'pos' to 'counter'.
    public void markAsVisited(Position pos, int counter)
    {    }

    // Set the status of the position 'pos' to 0;
    public void markAsBacktracked(Position pos)
    {    }

    // Check whether the knight finishes the traveling and finds a solution.
    public boolean done(Position pos)
    {    }

    // Print out the status for each position on the chessboard.
    // The output should be a two-dimensional table.
    public void display()
    {    }


    // A public method to return an Iterator which returns 
    // the eight neighbor positions one by one.
    public Iterator knightItr(Position pos)
    {
	return new KnightNeighbors(pos); 
    }

    // This is a private inner class implementing an Iterator Interface.
    private class KnightNeighbors implements Iterator
    {
	private int row;
	private int col;
	private int count = 0;

	public KnightNeighbors(Position pos)
	{
	    row = pos.getRow();
	    col = pos.getCol();
	}
	    
	public boolean hasNext()
	{
	    if (count <=7)
		return true;
	    return false;
	}

	public Object next()
	{
	    Position toBeReturn = null;
	    switch(count)
		{
		case 0:
		    toBeReturn = new Position(row-2, col+1); break;
		case 1:
		    toBeReturn = new Position(row-1, col+2); break;
		case 2: 
		    toBeReturn = new Position(row+1, col+2); break;
		case 3: 
		    toBeReturn = new Position(row+2, col+1); break;
		case 4: 
		    toBeReturn = new Position(row+2, col-1); break;
		case 5: 
		    toBeReturn = new Position(row+1, col-2); break;
		case 6: 
		    toBeReturn = new Position(row-1, col-2); break;
		case 7: 
		    toBeReturn = new Position(row-2, col-1); break;
		}	
	    count++;
	    return toBeReturn;
	}

	public void remove()
	{
	    throw new UnsupportedOperationException();
	}
    }
}
